<?php
// +----------------------------------------------------------------------
// | A3Mall
// +----------------------------------------------------------------------
// | Copyright (c) 2020 http://www.a3-mall.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: xzncit <158373108@qq.com>
// +----------------------------------------------------------------------

namespace app\install\controller;

use app\install\validate\Database;
use mall\utils\Tool;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Request;
use think\facade\Session;
use think\facade\View;
use app\install\controller\AlipayService;

class Pay{
    protected $path = '';

    public function index(){
        try{
            /*** 请填写以下配置信息 ***/
            $appid = '2021002125699282';  //https://open.alipay.com 账户中心->密钥管理->开放平台密钥，填写添加了电脑网站支付的应用的APPID
            $returnUrl = 'http://jdk.dfx666.com/install/pay/return';     //付款成功后的同步回调地址
            $notifyUrl = 'http://jdk.dfx666.com/install/pay/notify';     //付款成功后的异步回调地址
            $outTradeNo = uniqid();     //你自己的商品订单号
            $payAmount = 0.01;          //付款金额，单位:元
            $orderName = '支付测试';    //订单标题
            $signType = 'RSA2';			//签名算法类型，支持RSA2和RSA，推荐使用RSA2
            $rsaPrivateKey='MIIEowIBAAKCAQEAlbg0udYnOXSEc1hni90T5bfJGsRO0ET1Y2YJLIm3oFt0ItFfSd8ucLVpUJrpcA0cj+YOQWesWygN9ShakZ0FCy46vXu6/pKMtmurwyAHRz/UjyllfaZIAwest/SkbjoMy6I7r8kWLJY0EbnuGGLvdcgFTzm/o4WDCavX8/Jk4N+tsw6aSRNyLKPgDdRGiwIr+fIXgxVOlPUKGNDPrwlOgQxZFeGzGpbgbvWbUV49dwB8SR/gPDdtMMuvDY6pWbpPwxac/Mla+f4pB8V4Kfq+0vlyd2XQHu1xYsNfdftN4hoH6R146qEII59RIC7qsO742e7/1oQN0FOIPpLJ74shgQIDAQABAoIBAFv59wI3ao9kYj4OEEafASs9daEo+hX+VxXCSF6BGDq+FCGTqEtUfU4mVFV9ZW090M8iEJ3jl8HEYJa8PK952/BbbSCc02qzExi6GqHbmj0OHIH6d2vybAjYfSXhd+ZzaQrsVmiO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z6qoeZ';		//商户私钥，填写对应签名算法类型的私钥，如何生成密钥参考：https://docs.open.alipay.com/291/105971和https://docs.open.alipay.com/200/105310
            /*** 配置结束 ***/
            $aliPay = new AlipayService();
            $aliPay->setAppid($appid);
            $aliPay->setReturnUrl($returnUrl);
            $aliPay->setNotifyUrl($notifyUrl);
            $aliPay->setRsaPrivateKey($rsaPrivateKey);
            $aliPay->setTotalFee($payAmount);
            $aliPay->setOutTradeNo($outTradeNo);
            $aliPay->setOrderName($orderName);
            $sHtml = $aliPay->doPay();
            echo $sHtml;
            exit('over');

        }catch (\Exception $ex){
            echo $ex->getMessage();
            echo $ex->getLine();
        }
    }
    public function return(){
        $data = Request::param();
        echo '<pre>';
        print_r($data);
        echo '</pre>';
    }
    public function notify(){
        $data = Request::param();
        echo '<pre>';
        print_r($data);
        echo '</pre>';
    }

    public function config(){
        if(Request::isAjax()){
            $data = Request::param();
            try {
                validate(Database::class)->check($data);
            }catch (\Exception $ex){
                return json(["status"=>0,"msg"=>$ex->getMessage()]);
            }

            // 缓存配置数据
            $data['type'] = 'mysql';
            Session::set('installData', $data);

            try {

            } catch (\Exception $e) {
                return json(["status"=>0,"msg"=>$e->getMessage()]);
            }
        }
    }


}
